<script setup>
import LoginForm from "./components/LoginForm.vue";
import { useI18n } from "@/hooks/web/useI18n";
import { useAppStore } from "@/store/modules/app";
import { useDesign } from "@/hooks/web/useDesign";
import { ref, onMounted, onBeforeMount, onBeforeUnmount, nextTick } from "vue";
import WdCanvasNest from '@cwd/widgets/wd-canvas-nest'

const { getPrefixCls } = useDesign();

const prefixCls = getPrefixCls("login");

const appStore = useAppStore();

const { t } = useI18n();

const isLogin = ref(true);

const toRegister = () => {
  isLogin.value = false;
};

const toLogin = () => {
  isLogin.value = true;
};

// 模拟你原来的 screenWidth / fullWidth
const screenWidth = window.innerWidth;

const setCanvasClass = () => {
  const canvas = document.getElementsByTagName("canvas")[0];
  if (!canvas) return;

  if (window.innerWidth < 768) {
    canvas.removeAttribute("class");
  } else {
    canvas.className = "index_bg";
  }
};

// 页面加载时执行
onMounted(() => {
  nextTick(() => {
    setCanvasClass();
  });
  // 添加 resize 监听
  window.addEventListener("resize", setCanvasClass);
});

// 页面销毁时清除监听器和类名
onBeforeUnmount(() => {
  window.removeEventListener("resize", setCanvasClass);
  const canvas = document.getElementsByTagName("canvas")[0];
  if (canvas) {
    canvas.removeAttribute("class");
  }
});

setCanvasClass();
</script>

<template>
  <div
    :class="prefixCls"
    class="h-[100%]"
  >
    <ElScrollbar class="h-full login-page">
      <div
        class="flex mx-auto min-h-100vh justify-center items-center"
      >
        <div class="flex-1">
          <Transition
            appear
            enter-active-class="animate__animated animate__bounceInRight"
          >
            <div
              class="h-500px flex items-center m-auto w-[100%] at-2xl:max-w-500px at-xl:max-w-500px at-md:max-w-500px at-lg:max-w-500px"
              style="
                border: 1px solid #ccc;
                position: relative;
                overflow: hidden;
                background:#fff;
                z-index:10;
              "
            >
              <div class="plateform-tiile">渠道端</div>
              <LoginForm
                v-if="isLogin"
                class="h-auto w-[90%] m-auto"
                @to-register="toRegister"
              />
            </div>
          </Transition>
        </div>
      </div>
    </ElScrollbar>
  </div>
  <WdCanvasNest></WdCanvasNest>
</template>

<style lang="less" scoped>
@prefix-cls: ~"@{adminNamespace}-login";

.@{prefix-cls} {
  overflow: auto;

 

}
.login-page{
  background: none;
  background-image: url("@/assets/imgs/login_bg.jpg");
}
.plateform-tiile {
  position: absolute;
  color: #999;
  transform: rotate(45deg);
  right: -75px;
  top: -75px;
  border-bottom: 1px solid #fff;
  width: 150px;
  height: 150px;
  display: flex;
  justify-content: center;
  color: #fff;
  align-items: flex-end;
  padding-bottom: 20px;
  background: linear-gradient(to right, #036fff, #0295ff);
  z-index: 30;
}
.index_bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6) !important;
  z-index: 0 !important;
}
</style>
